package com.weixin.paleituo.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.weixin.paleituo.R;
import com.weixin.paleituo.activity.BuyHouseStepActivity;
import com.weixin.paleituo.activity.LoginActivity;
import com.weixin.paleituo.activity.RefundActivity;
import com.weixin.paleituo.application.BaseApplication;
import com.weixin.paleituo.base.BaseRecycleAdapter;
import com.weixin.paleituo.bean.BuyHuseBean;
import com.weixin.paleituo.help.RecycleViewHolder;
import com.weixin.paleituo.help.RecycleViewOnItemOnclickListener;
import com.weixin.paleituo.util.UIUtils;

import java.util.List;

/**
 * Author yichao
 * Time  2018/1/15 14:43
 * Dest 购房清单
 */

public class BuyHouseListAdapter extends BaseRecycleAdapter<BuyHuseBean> {
    private RecycleViewOnItemOnclickListener mListener;
    private TextView mTvPosition;
    private TextView mTvTime;
    private ImageView mIvIcon;
    private TextView mTvHouseName;
    private ImageView mIvStep;
    private TextView mTvStep;

    public BuyHouseListAdapter(Context context, List<BuyHuseBean> datas) {
        super(context, datas, R.layout.item_buyhouselist_layout);
    }

    @Override
    protected void setData(final RecycleViewHolder holder, final BuyHuseBean buyHuseBean, final int position) {
        mTvPosition = holder.getItemView(R.id.tv_position_item_buyhouselist_layout);
        mTvTime = holder.getItemView(R.id.tv_time_item_buyhouselist_layout);
        mIvIcon = holder.getItemView(R.id.iv_item_buyhouselist_layout);
        mTvHouseName = holder.getItemView(R.id.tv_house_name_item_buyhouselist_layout);
        mIvStep = holder.getItemView(R.id.iv_step_item_buyhouselist_layout);
        mTvStep = holder.getItemView(R.id.tv_setp_item_buyhouselist_layout);

        /*5-退款、1-预定、2-签约、3-收房、4-入住）*/
     final    int roomState = buyHuseBean.getRoomState();
        switch (roomState) {
            case 1:
                mTvStep.setText("预定");
                mTvStep.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
                mIvStep.setImageResource(R.mipmap.reserve2);
                break;
            case 2:
                mTvStep.setText("签约");
                mTvStep.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
                mIvStep.setImageResource(R.mipmap.sign2);
                break;
            case 3:
                mTvStep.setText("收房");
                mTvStep.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
                mIvStep.setImageResource(R.mipmap.collect1_house);
                break;
            case 4:
                mTvStep.setText("入住");
                mTvStep.setTextColor(UIUtils.getColor(R.color.c_29CE7E));
                mIvStep.setImageResource(R.mipmap.check_in1);
                break;
            case 5:
                mTvStep.setTextColor(UIUtils.getColor(R.color.c_5dc7fd));
                mTvStep.setText("退款");
                mIvStep.setImageResource(R.mipmap.refund);
                break;
        }
        mTvTime.setText(buyHuseBean.getAdvanceTime() + "");
        mTvPosition.setText(buyHuseBean.getFullName() + "");
        mTvHouseName.setText(buyHuseBean.getHouses() + "");
        Glide.with(mContext).load(buyHuseBean.getImgUrl() + "").into(mIvIcon);
        holder.mItemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //  mListener.onItemClick(v,holder,position);
         if (roomState==5){
             if (BaseApplication.isLoginSuccess){
             //退款界面
             RefundActivity.startActivity(mContext,buyHuseBean.getOrderId());
             }else {
                 LoginActivity.startActivity(mContext,true);
             }

         }else {
             if (BaseApplication.isLoginSuccess){

                 //购房流程
                BuyHouseStepActivity.startActivity(mContext, buyHuseBean.getId() + "",BaseApplication.sUserInfoBean.username);
             }else {
                 LoginActivity.startActivity(mContext,true);
             }



         }



            }
        });

    }


}
